/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.persistence.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author clayton
 */
@Entity 
@Table(name = "category")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c"),
    @NamedQuery(name = "Category.findByCategoryId", query = "SELECT c FROM Category c WHERE c.categoryId = :categoryId"),
    @NamedQuery(name = "Category.findByCategoryName", query = "SELECT c FROM Category c WHERE c.categoryName = :categoryName")
})
public class Category implements Serializable 
{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "category_id")
    private Long categoryId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 256)
    @Column(name = "category_name")
    private String categoryName;
    @JoinTable(name = "category_parent", joinColumns =
    {
        @JoinColumn(name = "category_id", referencedColumnName = "category_id")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "category_parent_id", referencedColumnName = "category_id")
    })
    @ManyToMany
    private Collection<Category> categoryCollection;
    @ManyToMany(mappedBy = "categoryCollection")
    private Collection<Category> categoryCollection1;
    @ManyToMany(mappedBy = "categoryCollection")
    private Collection<Kungkhie> kungkhieCollection;
    @JoinTable(name = "category_alias", joinColumns =
    {
        @JoinColumn(name = "category_id", referencedColumnName = "category_id")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "alias_id", referencedColumnName = "alias_id")
    })
    @ManyToMany
    private Collection<AliasTerm> aliasTermCollection;

    public Category()
    {
    }

    public Category(Long categoryId)
    {
        this.categoryId = categoryId;
    }

    public Category(Long categoryId, String categoryName)
    {
        this.categoryId = categoryId;
        this.categoryName = categoryName;
    }

    public Long getCategoryId()
    {
        return categoryId;
    }

    public void setCategoryId(Long categoryId)
    {
        this.categoryId = categoryId;
    }

    public String getCategoryName()
    {
        return categoryName;
    }

    public void setCategoryName(String categoryName)
    {
        this.categoryName = categoryName;
    }

    @XmlTransient
    public Collection<Category> getCategoryCollection()
    {
        return categoryCollection;
    }

    public void setCategoryCollection(Collection<Category> categoryCollection)
    {
        this.categoryCollection = categoryCollection;
    }

    @XmlTransient
    public Collection<Category> getCategoryCollection1()
    {
        return categoryCollection1;
    }

    public void setCategoryCollection1(Collection<Category> categoryCollection1)
    {
        this.categoryCollection1 = categoryCollection1;
    }

    @XmlTransient
    public Collection<Kungkhie> getKungkhieCollection()
    {
        return kungkhieCollection;
    }

    public void setKungkhieCollection(Collection<Kungkhie> kungkhieCollection)
    {
        this.kungkhieCollection = kungkhieCollection;
    }

    @XmlTransient
    public Collection<AliasTerm> getAliasTermCollection()
    {
        return aliasTermCollection;
    }

    public void setAliasTermCollection(Collection<AliasTerm> aliasTermCollection)
    {
        this.aliasTermCollection = aliasTermCollection;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (categoryId != null ? categoryId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Category))
        {
            return false;
        }
        Category other = (Category) object;
        if ((this.categoryId == null && other.categoryId != null) || (this.categoryId != null && !this.categoryId.equals(other.categoryId)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "com.kungkhies.persistence.entities.Category[ categoryId=" + categoryId + " ]";
    }

}
